﻿using Caiji.Models;
using Caiji.OpCommand;
using Caiji.UserControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Caiji.ViewModels
{
    class MainWindowModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;
        //通知 UI 属性值已变更
        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            /*
                      //确保只有存在事件订阅者时才触发
                     if (PropertyChanged != null)
                     {
                         PropertyChangedEventHandler handler = this.PropertyChanged;
                         //this：事件源（通常是当前 ViewModel 或窗口）。

                         //PropertyChangedEventArgs：封装要通知的属性名。
                             handler(this, new PropertyChangedEventArgs(propertyName));

                     }
             */

        }
        //监控用户控件
        UserControl _uc;
        public UserControl uc
        {
            get { 
                if(_uc == null)
                {
                    _uc = new UC();
                }
                return _uc;
            }
            set
            {
                _uc = value;
                RaisePropertyChanged("UC");
            }
        }
        //时分
       string _timeStr;
       public string TimeStr {
            get {
                if (_timeStr == null)
                {
                    _timeStr = DateTime.Now.ToString("HH:mm");
                }
                return _timeStr;
            }
            set
            {
                _timeStr = value;
                RaisePropertyChanged("UC");
            }
        }
        //年月日
        string _ymd;
        public string Ymd
        {
            get
            {
                if(_ymd == null)
                {
                    _ymd = DateTime.Now.ToString("yy-MM-dd");
                }
                return _ymd;
            }
            set
            {
                _ymd = value;
                RaisePropertyChanged("UC");
            }
        }
        //星期
        string _week;
        public string Week
        {
            get
            {
                if(_week == null)
                {
                    _week = DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-CN"));
                }
                return _week;
            }
            set
            {
                _week = value;
                RaisePropertyChanged("UC");
            }
        }
        //几台总数
        string _myVar="0298";
        public string MyVar
        {
            get
            {
                return _myVar;
            }
            set
            {
                _myVar = value;
                RaisePropertyChanged("UC");
            }
        }
        List<EnvironmentModel> _evcoronmentList = new List<EnvironmentModel> { 
            new EnvironmentModel{Name = "光照(Lux)",Value= "1"},
             new EnvironmentModel{Name = "温度（C)",Value= "13"},
              new EnvironmentModel{Name = "湿度(%)",Value= "33.1"},
               new EnvironmentModel{Name = "PM2.5(m²)",Value= "3.0"},
                 new EnvironmentModel{Name = "硫化氢(PPM)",Value= "15"},
                 new EnvironmentModel{Name = "氮气(PPM)",Value= "18.0"}
        };
        public List<EnvironmentModel> EvcoronmentList
        {
            get
            {
                return _evcoronmentList;
            }
            set
            {
                _evcoronmentList = value;
                RaisePropertyChanged("UC");
            }
        }
        //列表数据
         List<AlarmModel> _alarmLs = new List<AlarmModel>
        {
            new AlarmModel{ Num = "1", Msg="温度过高",Time = DateTime.Now.ToString("yy-MM-dd HH:mm:ss"), Duration=7},
             new AlarmModel{ Num = "2", Msg="湿度过高",Time = DateTime.Now.ToString("yy-MM-dd HH:mm:ss"), Duration=77},
              new AlarmModel{ Num = "3", Msg="温度过低",Time = DateTime.Now.ToString("yy-MM-dd HH:mm:ss"), Duration=17},
               new AlarmModel{ Num = "4", Msg="温度过低",Time = DateTime.Now.ToString("yy-MM-dd HH:mm:ss"), Duration=70},
        };
        public List<AlarmModel> AlarmLs
        {
            get
            {
                return _alarmLs;
            }
            set
            {
                _alarmLs = value;
                RaisePropertyChanged("UC");
            }
        }

        List<EnvironmentModel> _machineData = new List<EnvironmentModel>
        {
            new EnvironmentModel{ Value  = "69.8", Name ="电能" },
            new EnvironmentModel{Value = "390" ,Name="电压"},
            new EnvironmentModel{Value = "5",Name = "电能"},
            new EnvironmentModel{Value = "13",Name="压差"},
            new EnvironmentModel{Value = "36",Name="温度"},
            new EnvironmentModel{Value = "4.1",Name="震动"},
            new EnvironmentModel{Value = "2600",Name="转速"},
            new EnvironmentModel{Value = "0.5",Name="气压"}
        };
        public List<EnvironmentModel> MachineData
        {
            get { return _machineData; }
            set
            {
                _machineData = value;
                RaisePropertyChanged("UC");
            }
        }
        //雷达数据群
         List<EnvironmentModel> _reach = new List<EnvironmentModel>
         {
                         new EnvironmentModel{ Value  = "69.8", Name ="电能" },
            new EnvironmentModel{Value = "390" ,Name="电压"},
            new EnvironmentModel{Value = "5",Name = "电能"},
            new EnvironmentModel{Value = "13",Name="压差"},
            new EnvironmentModel{Value = "36",Name="温度"},
            new EnvironmentModel{Value = "4.1",Name="震动"},
            new EnvironmentModel{Value = "2600",Name="转速"},
            new EnvironmentModel{Value = "0.5",Name="气压"}
         };
        public List<EnvironmentModel> Reach
        {
            get { return _reach; }
            set
            {
                _reach = value;
                RaisePropertyChanged("Reach");
            }
        }
        List<ReachCanvas> _lei = new List<ReachCanvas> {
            new ReachCanvas{Name="排烟风机",Value=90},
            new ReachCanvas{Name="客梯",Value=30},
            new ReachCanvas{Name="供水机",Value=35},
            new ReachCanvas{Name="喷淋水泵",Value=69},
            new ReachCanvas{Name="稳压设备",Value=20}
        };

        public List<ReachCanvas> Lei
        {
            get
            {
                return _lei;
            }
            set
            {
                _lei = value;
                RaisePropertyChanged("Reach");
            }
        }
        public List<Staff> _sta = new List<Staff> { 
        new Staff{Name="张晓婷",position="技术员",cout=123},
        new Staff{Name="李晓",position="操作员",cout=23},
        new Staff{Name="王克检",position="技术员",cout=134},
        new Staff{Name="杨过",position="技术员",cout=143},
        new Staff{Name="欧阳克",position="技术员",cout=12}
            };
        public List<Staff> Sta
        {
            get { return _sta; }
            set
            {
                _sta = value;
                RaisePropertyChanged("UC");
            }
        }
        public List<Che> _total = new List<Che>
        {
            new Che
            {
                Name = "贴片车间",
                Zong = 44,
                Zuo = 32,
                Deng = 8,
                Gu = 4,
                Ting = 0
            },
            new Che
            {
                Name = "封装车间",
                Zong = 32,
                Zuo = 20,
                Deng = 8,
                Gu = 4,
                Ting = 0
            },
            new Che
            {
                Name = "焊接车间",
                Zong = 44,
                Zuo = 32,
                Deng = 8,
                Gu = 4,
                Ting = 0
            },
            new Che
            {
                Name = "贴片车间",
                Zong = 44,
                Zuo = 32,
                Deng = 8,
                Gu = 4,
                Ting = 0
            }
        };
        public List<Che> Totol
        {
            get { return _total; }
            set
            {
                _total = value;
                RaisePropertyChanged("UC");
            }
        }
        public List<MachineModel> _ls = null ;
        public List<MachineModel> Ls
        {
            get { 
                if(_ls == null)
                {
                    _ls = new List<MachineModel>();
                    var random = new Random();
                    for(int i = 0; i < 20; i++)
                    {
                        int plan = random.Next(100, 1000);
                        int complete = random.Next(0,plan);
                        _ls.Add(new MachineModel
                        {
                            MachineName = "焊接机-" + (i + 1),
                            FinishedCount = complete,
                            PlanCount = plan,
                            Status = "作业中",
                            OrderNo = "H202212345678"
                        });
                    }
                }
                return _ls;
            } 
            set
            {
                _ls = value;
                RaisePropertyChanged(nameof(CheDetail));
            }
        }
        public Commands ShowDetails { get { return new Commands(ShowDetailsFun); } }

        private void ShowDetailsFun()
        {
            
        }
    }
}
